part of '../repository.dart';

const _kPreviouslyKnownLexicalItemProgressTimeKey = 'time';

const _kPreviouslyKnownLexicalItemProgressTypeValue = 'previously_known';

class _PreviouslyKnownLexicalItemProgressDto extends Equatable implements _LexicalItemProgressDto {
  const _PreviouslyKnownLexicalItemProgressDto._internal({
    required this.additionTimeDto,
  });

  final _TimeDto additionTimeDto;

  @override
  String get type => _kPreviouslyKnownLexicalItemProgressTypeValue;

  @override
  List<Object?> get props {
    return [
      additionTimeDto,
    ];
  }

  factory _PreviouslyKnownLexicalItemProgressDto.fromJson(Map<String, dynamic> json) {
    final additionTimeMap = json[_kPreviouslyKnownLexicalItemProgressTimeKey] as Map;

    final additionTimeJson = Map.castFrom<dynamic, dynamic, String, dynamic>(additionTimeMap);

    final additionTimeDto = _TimeDto.fromJson(additionTimeJson);

    return _PreviouslyKnownLexicalItemProgressDto._internal(
      additionTimeDto: additionTimeDto,
    );
  }

  factory _PreviouslyKnownLexicalItemProgressDto.fromEntity(
      PreviouslyKnownLexicalItemProgress previouslyKnownLexicalItemProgress) {
    return _PreviouslyKnownLexicalItemProgressDto._internal(
      additionTimeDto: _TimeDto.fromEntity(previouslyKnownLexicalItemProgress.time),
    );
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      _kLexicalItemProgressTypeKey: type,
      _kPreviouslyKnownLexicalItemProgressTimeKey: additionTimeDto.toJson(),
    };
  }

  @override
  PreviouslyKnownLexicalItemProgress toEntity() {
    return PreviouslyKnownLexicalItemProgress(
      time: additionTimeDto.toEntity(),
    );
  }
}
